package easy.com.sk.config;

import com.easy.common.util.SYS;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SKMQConfig {


    @Bean
    public Queue skQueue()
    {
        Queue queue = new Queue(SYS.SK_QUEUE);
        return queue;
    }
    // 死信队列   秒杀失败的队列
    @Bean
    public Queue dlxQueue()
    {
        Queue queue = new Queue(SYS.SK_DLX_QUEUE);
        return queue;
    }

    @Bean
    public DirectExchange skExchange()
    {
        DirectExchange exchange = new DirectExchange(SYS.SK_EXCHANGE);
        return exchange;
    }

    // 绑定队列
    @Bean
    public Binding skBinding(@Qualifier("skQueue") Queue skQueue, @Qualifier("skExchange") DirectExchange skExchange){
        return BindingBuilder.bind(skQueue).to(skExchange).with(SYS.SK_ROUTING_KEY);
    }

    // 绑定死信队列
    @Bean
    public Binding skDLXBinding(@Qualifier("dlxQueue") Queue dlxQueue, @Qualifier("skExchange") DirectExchange skExchange){
        return BindingBuilder.bind(dlxQueue).to(skExchange).with(SYS.SK_DLX_ROUTING_KEY);
    }
}






























